// JavaScript Class
class createAjax {
    constructor(url,type,headers,data){
        this.url=url;
        this.type=type;
        this.headers=headers||{};
        this.data=data||{};
    }

    sendRequest(successCallback,errorCallback){
        $.ajax({
            url: this.url,
			headers: this.headers,
            type: this.type,
            data: this.data,
            success: function(data) {
				if(data['code']==1001 && !window.location.href.includes('index.html')) {
					alert(data['msg']);
					window.location.href='loginPage.html';
				}
                if(typeof successCallback === 'function') successCallback(data);
				else alert('客户端调试->successCallback()：无效的方法！')
            },
            error: function(error) {
                if (typeof errorCallback === 'function') errorCallback(error);
				else {
					alert('请求异常!');
					console.log(error);
				}
            }
        });
    }
}